package cn.schoolwow.util.test.module.crypto.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.crypto.messageDigest.MessageDigest;
import cn.schoolwow.util.domain.crypto.messageDigest.MessageDigestType;
import org.junit.Assert;

import java.io.File;

public class MessageDigestTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String data = "hello,world!";

        MessageDigest messageDigest = MessageDigest.newMessageDigest()
                .data(data);
        {
            String digestMessage = messageDigest.messageDigestType(MessageDigestType.MD5).getHexString();
            Assert.assertEquals("c0e84e870874dd37ed0d164c7986f03a", digestMessage);
        }
        {
            String digestMessage = messageDigest.messageDigestType(MessageDigestType.SHA1).getHexString();
            Assert.assertEquals("4518135c05e0706c0a34168996517bb3f28d94b5", digestMessage);
        }
        {
            String digestMessage = messageDigest.messageDigestType(MessageDigestType.SHA256).getHexString();
            Assert.assertEquals("ec1e0bd875226943ad0e8877bdba4ca449c4cb8591a5363921c9f1ee20084c34", digestMessage);
        }
        {
            String digestMessage = messageDigest.messageDigestType(MessageDigestType.SHA512).getHexString();
            Assert.assertEquals("fa9edcfdaab7a4165f8d2593f04077d46aca957493e7e181ca479582d519a299d967305294d5d46fb5e0158240441b94cd96510c2311bdc86870e5ebf3efe60c", digestMessage);
        }
        {
            File file = new File("C:/Users/SY/Downloads/docker-20.10.9.tar");
            String digestMessage = messageDigest.messageDigestType(MessageDigestType.MD5).file(file).getFileHexString();
            Assert.assertEquals("6fd3efacdb3f712061252d02f80b9fe6", digestMessage);
        }
    }

    @Override
    public String name() {
        return "散列算法测试用例";
    }
}
